import json
from dataclasses import dataclass


# @dataclass类似于lombok的@Data
@dataclass
class User(object):
    # python的id是关键字，所以不拿来映射逻辑主键了
    # id: int
    # 测试任务id
    username: str
    # 测试任务名称
    password: str
    nickname: str

    def __init__(self):
        self.username = ''
        self.password = ''
        self.nickname = ''

    # 遍历所有属性的key，方便转换成dict后打印成json
    def keys(self):
        return ('username', 'password', 'nickname')

    def __getitem__(self, item):
        return getattr(self, item)

    def __str__(self):
        return json.dumps(dict(self.__dict__))

    def __repr__(self):
        return self.__str__()
